/*
 * Copyright (C) Michael Opitz
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
 * USA
 */
#ifndef TIMEOUT_H
#define TIMEOUT_H

#include <boost/function.hpp>
#include "pthread.h"


/** 
 * \brief This namespace includes all-purpose classes.
 * \author Michael Opitz
 */
namespace core {
	/** 
	 * \brief timeout_doit is a helper function, you shouldn't care about
	 * this function
	 * 
	 * \param timeout 
	 */
	void* timeout_doit(void *timeout);
	/** 
	 * \brief This class provides a timeout-functionality. 
	 */
	class timeout {
	friend void* timeout_doit(void *);
	public:
		/** 
		 * This constructor creates a timeout-object. If your callback
		 * lasts longer as the duration it will be interrupted. Please
		 * mind that your callback-function could be in a non-consistend
		 * state after an interruption.
		 * \brief timeout creates a timeout-object.
		 * 
		 * \param f is the callback which should be called
		 * \param sek is the duration, after which the callback should
		 * be cancelled
		 */
		timeout(const boost::function0<void> &f, int sek);
		~timeout() {};
	private:
		const boost::function0<void> &_f;
		int _sek;
	};
}

#endif
